<template>
  <Content :title="optionData.type ? '确认' : '驳回'">
    <view class="quality-confirmation-box">
      <u-form
        labelPosition="top"
        :model="model"
        labelWidth="200"
        labelAlign="left"
        :rules="rules"
        ref="uForm"
      >
        <u-form-item
          :label="optionData.desc"
          prop="approveComment"
          labelPosition="top"
          required
        >
          <u-textarea
            style="margin-top: 20px"
            v-model="model.approveComment"
            placeholder="请输入"
          ></u-textarea>
        </u-form-item>
        <view class="btn-v">
          <view class="but-box">
            <u-button class="btn" @click="close" text="取消"></u-button>
            <u-button
              class="btn"
              type="primary"
              @click="submit"
              text="确定"
            ></u-button>
          </view>
        </view>
      </u-form>
    </view>
  </Content>
</template>

<script>
import Content from "@/components/content/index.vue";
import { getPageData } from "@/store/user";
import fetch from "@/utils/fetch";
export default {
  components: {
    Content,
  },
  data() {
    return {
      id: "",
      model: {
        approveComment: "",
      },
      rules: {
        approveComment: {
          required: true,
          message: "请填写",
          trigger: ["blur", "change"],
        },
      },
      optionData: {
        type: true,
      },
    };
  },
  onLoad: function (option) {
    //option为object类型，会序列化上个页面传递的参数
  },
  onShow: function () {},
  mounted() {
    console.log(this.optionData, "this.optionData");
    this.optionData = getPageData();
  },
  methods: {
    close() {
      uni.navigateBack({
        delta: 1,
      });
    },
    submit() {
      const that = this;
      const approveComment = that.model.approveComment;
      let data = {
        id: that.optionData.id,
      };
      data[that.optionData.key] = that.model.approveComment;
      that.$refs.uForm.validate().then((valid) => {
        if (valid) {
          that.$loading.open();
          fetch("post", that.optionData.url, data).then((res) => {
            console.log(11111111111);
            uni.$emit("openToast", {
              type: "success",
              title: "操作成功",
              complete() {
                uni.navigateBack({
                  delta: 1,
                });
              },
            });
          });
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.quality-confirmation-box {
  padding: 40rpx;
  background-color: #fff;
  min-height: 100%;
}
</style>
